import type { MultipleConditionSearchSchema } from '@/components/multiple-condition-search'

export default function useConfig() {
  const searchSchema = computed<MultipleConditionSearchSchema>(() => {
    return {
      placeholder: '默认按照规则 ID 搜索',
      maxWidth: 232,
      widgets: [
        {
          type: 'input',
          label: '规则 ID',
          field: 'id',
          message: '规则 ID 格式不正确',
          validate: validateRuleID,
          maxLength: 19,
        },
        {
          type: 'input',
          label: '规则名称',
          field: 'name_keyword',
        },
      ],
    }
  })

  const tableColumns = buildColumns([
    {
      width: 48,
      dataIndex: 'sort',
      slotName: 'sort',
    },
    {
      title: '优先级',
      width: 68,
      dataIndex: 'priority',
    },
    {
      title: '规则 ID',
      dataIndex: 'id',
      format: 'copy',
    },
    {
      title: '规则名称',
      dataIndex: 'name',
      format: 'copy',
    },
    {
      title: '规则描述',
      width: 177,
      dataIndex: 'condition_description',
      slotName: 'condition_description',
    },
    {
      title: '跳过模块',
      width: 147,
      dataIndex: 'skip_module',
      slotName: 'skip_module',
    },
    {
      title: '部署节点',
      width: 88,
      dataIndex: 'node_bind_count',
      slotName: 'node_bind_count',
    },
    {
      title: '状态',
      width: 64,
      dataIndex: 'status',
      slotName: 'status',
    },
    {
      title: '更新时间',
      width: 151,
      dataIndex: 'created_at',
      slotName: 'created_at',
      format: 'date-time',
      sortable: sortableSettings,
    },
    {
      title: '操作',
      fixed: 'right',
      slotName: 'actions',
      width: 80,
      cellClass: 'actions-cell',
    },
  ])

  return {
    searchSchema,
    tableColumns,
  }
}
